/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package SocketServer;

import java.io.IOException;
import java.net.ServerSocket;

/**
 *
 * @author Santos
 */
public class ServidorSocket {

    /**
     * Instancia do modelo da classe servidor socket
     */
    private ServidorSocketModel model = new ServidorSocketModel();

    /**
     * Configura e executa o servidor de socket além fica aguardando as conexão
     * dos clientes
     *
     * @throws java.io.IOException
     * @throws java.lang.ClassNotFoundException
     */
     public void runServer() throws IOException, ClassNotFoundException {

        //configura o servidor para receber conexões
        ServerSocket server = new ServerSocket(model.getPortaSocket());
        //processa as conexões dos clientes
        while (true) {
            System.out.println("Aguardando cliente se conectar: ");
            model.setSocketCliente(server.accept());
            System.out.println("Conexão efetuada com: " + model.getSocketCliente().getInetAddress().getHostName());

            //Passa para a classe de controle o gerenciamento da conexão do cliente e inicia o jogo
            ServidorSocketControl control = new ServidorSocketControl(model.getSocketCliente());
            Thread thread = new Thread(control);
            thread.start();
        }
    }
}
